from __future__ import annotations

from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
from sqlmodel import Session

from app.core.db import engine
from .service import update_reminders


def create_scheduler() -> BackgroundScheduler:
    scheduler = BackgroundScheduler()

    def job() -> None:
        with Session(engine) as session:
            update_reminders(session)

    # 默认：每天 09:00 触发；可通过环境变量改造
    scheduler.add_job(job, CronTrigger(day_of_week='*', hour='9', minute='0'))
    return scheduler


